package com.ruoyi.project.information.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.information.domain.RyContractTemplate;
import com.ruoyi.project.information.service.IRyContractTemplateService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 合同模板Controller
 *
 * @author 萧雪
 * @date 2022-10-25
 */
@RestController
@RequestMapping("/information/ryContractTemplate")
public class RyContractTemplateController extends BaseController
{
    @Autowired
    private IRyContractTemplateService ryContractTemplateService;

    /**
     * 查询合同模板列表
     */
    @PreAuthorize("@ss.hasPermi('information:ryContractTemplate:list')")
    @GetMapping("/list")
    public TableDataInfo list(RyContractTemplate ryContractTemplate)
    {
        startPage();
        List<RyContractTemplate> list = ryContractTemplateService.selectRyContractTemplateList(ryContractTemplate);
        all(ryContractTemplate);
        return getDataTable(list);
    }
    /**
     * 查询所有合同模板列表
     */
    @PreAuthorize("@ss.hasPermi('information:ryContractTemplate:list')")
    @GetMapping("/all")
    public TableDataInfo all(RyContractTemplate ryContractTemplate)
    {
        // startPage();
        List<RyContractTemplate> list = ryContractTemplateService.selectRyContractTemplateList(ryContractTemplate);
        System.out.println(list);
        return getDataTable(list);
    }

    /**
     * 导出合同模板列表
     */
    @PreAuthorize("@ss.hasPermi('information:ryContractTemplate:export')")
    @Log(title = "合同模板", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RyContractTemplate ryContractTemplate)
    {
        List<RyContractTemplate> list = ryContractTemplateService.selectRyContractTemplateList(ryContractTemplate);
        ExcelUtil<RyContractTemplate> util = new ExcelUtil<RyContractTemplate>(RyContractTemplate.class);
        util.exportExcel(response, list, "合同模板数据");
    }

    /**
     * 获取合同模板详细信息
     */
    @PreAuthorize("@ss.hasPermi('information:ryContractTemplate:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(ryContractTemplateService.selectRyContractTemplateById(id));
    }

    /**
     * 新增合同模板
     */
    @PreAuthorize("@ss.hasPermi('information:ryContractTemplate:add')")
    @Log(title = "合同模板", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RyContractTemplate ryContractTemplate)
    {
        return toAjax(ryContractTemplateService.insertRyContractTemplate(ryContractTemplate));
    }

    /**
     * 修改合同模板
     */
    @PreAuthorize("@ss.hasPermi('information:ryContractTemplate:edit')")
    @Log(title = "合同模板", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RyContractTemplate ryContractTemplate)
    {
        return toAjax(ryContractTemplateService.updateRyContractTemplate(ryContractTemplate));
    }

    /**
     * 删除合同模板
     */
    @PreAuthorize("@ss.hasPermi('information:ryContractTemplate:remove')")
    @Log(title = "合同模板", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(ryContractTemplateService.deleteRyContractTemplateByIds(ids));
    }
}
